from django.db import models

# Create your models here.


class QUser(models.Model):
    username = models.CharField(max_length=32, verbose_name="账号")
    password = models.CharField(max_length=32, verbose_name="密码")
    nick_name = models.CharField(max_length=32, verbose_name="昵称", null=True, blank=True)
    gender = models.CharField(max_length=2, verbose_name="性别", default="男")
    phone = models.CharField(max_length=11, verbose_name="手机号", null=True, blank=True)
    email = models.CharField(max_length=32, verbose_name="邮箱", null=True, blank=True)
    picture = models.ImageField(upload_to="images", verbose_name="头像", default="1.jpg")
    address = models.TextField(verbose_name="地址", null=True, blank=True)
    user_type = models.IntegerField(verbose_name="用户类型",default=0)  # 0 代表买家， 1表示买家

    class Meta:
        db_table = "queser"  # 修改表命名


class Store(models.Model):
    s_name = models.CharField(max_length=32, verbose_name="店铺名字")
    s_logo = models.ImageField(upload_to="images", default="1.jpg", verbose_name="商品logo")
    s_address = models.TextField(null=True, blank=True, verbose_name="店铺地址")
    s_description = models.TextField(null=True, blank=True, verbose_name="店铺描述")
    s_user = models.OneToOneField(to=QUser, on_delete=models.CASCADE, verbose_name="与Quser一对一")

    class Meta:
        db_table = "store"


class GoodsType(models.Model):   ## appname_goodstype
    t_name = models.CharField(max_length=32,verbose_name="类型名字")
    t_img = models.ImageField(upload_to="images",default="1.jpg",verbose_name="商品类型图片")
    t_description = models.TextField(null=True,blank=True,verbose_name="类型描述")

    class Meta:
        db_table='goodstype'    ####    goodstype


class Goods(models.Model):
    g_name = models.CharField(max_length=32,verbose_name="商品名字")
    g_number = models.CharField(max_length=32,verbose_name="商品编号")
    g_price  = models.FloatField(verbose_name="商品价格")
    g_safe_date = models.IntegerField(verbose_name="商品保质期")
    g_description = models.TextField(verbose_name="商品描述")
    g_picture = models.ImageField(upload_to="images",verbose_name="商品图片")
    g_num = models.IntegerField(verbose_name="商品数量")
    g_type = models.ForeignKey(to=GoodsType,on_delete=models.CASCADE,verbose_name="商品类型外键")
    g_store = models.ForeignKey(to=Store,on_delete=models.CASCADE,verbose_name="商品店铺")

    class Meta:
        db_table = "goods"


class GoodsImg(models.Model):
    img_path = models.ImageField(upload_to="images",verbose_name="商品图片")
    img_description = models.TextField(verbose_name="图片描述")
    img_name = models.CharField(max_length=32,verbose_name="图片名字")
    goods = models.ForeignKey(to=Goods,on_delete=models.CASCADE,verbose_name="商品外键")

    class Meta:
        db_table = "goodsimg"
